package cate.game.activity.herodirectbuy.msg;

import cate.game.GameBody;
import cate.game.activity.herodirectbuy.HeroDirectBuyPO;
import cate.game.client.msg.ClientMsg;
import cate.game.client.msg.MsgConfig;
import cate.game.client.msg.MsgInputTemplate;
import cate.game.client.msg.id.MsgIdBHeroDirectBuy;
import cate.game.role.Role;
import easy.java.dev.note.NoteField;
import easy.java.practice.errorcode.EcResult;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@ClientMsg(title = "英雄直购-购买 请求")
public class DirectBuyReq extends MsgInputTemplate {

    @NoteField("功能ID")
    public int funcId;
    @NoteField("配置ID")
    public int tid;
    @Override
    public MsgConfig conf() {
        return MsgIdBHeroDirectBuy.DIRECT_BUY_REQ;
    }

    @Override
    public void action(GameBody game, Role role) throws Exception {
        HeroDirectBuyPO single = role.getActivity().getEnableActivitySingle(funcId);
        if (single == null) {
            game.notice.message(role, "活动未开启");
            return;
        }
        EcResult<Void> r = single.buyItem(tid);
        if (!r.ok()) {
            game.notice.message(role, r.message);
        }
    }
}
